package cn.wolfcode.qo;

import lombok.Data;

import java.util.List;

/**
 * @author Ian
 * @date 2021/4/19 13:35
 */
@Data
public class PageResult<T> {
    private Integer totalCount;
    private List<T> data;

    private Integer currentPage;
    private Integer pageSize;

    private Integer totalPage;
    private Integer prevPage;
    private Integer nextPage;

    public PageResult(Integer totalCount, List<T> data, Integer currentPage, Integer pageSize) {
        this.totalCount = totalCount;
        this.data = data;
        this.currentPage = currentPage;
        this.pageSize = pageSize;

        this.totalPage = this.totalCount % this.pageSize == 0 ?
                this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1;
        this.prevPage = this.currentPage - 1 >= 1 ? this.currentPage - 1 : 1;
        this.nextPage = this.currentPage + 1 <= this.totalPage ? this.currentPage + 1 : this.totalPage;
    }
}
